% araim

HestenesJacobiComputation($r_1$ : sparse vector with $length_1$ tuples, $r_2$ : sparse vector with $length_2$ tuples)

\begin{algorithmic}
\STATE $j_1 \gets 1$, $j_2 \gets 1$, $norm_1 \gets 0$, $norm_2 \gets 0$, $dotprod \gets 0$

\IF {$r_1 = r_2$}
\STATE return $c, s \gets 1, 0$
\ENDIF

\WHILE{$j_1 \leq length_1$ and $j_2 \leq length_2$}
  \IF {$i_{1, j_1} < i_{2, j_2}$}
    \STATE $norm_1 \gets norm_1 + v_{1, j_1}$
    \STATE $j_1 \gets j_1 + 1$
  \ELSIF {$i_{1, j_1} > i_{2, j_2}$}
    \STATE $norm_2 \gets norm_2 + v_{2, j_2}$
    \STATE $j_2 \gets j_2 + 1$
  \ELSE
    \STATE $dotprod \gets dotprod + v_{1, j_1}^T v_{2, j_2}$
    \STATE $norm_1 \gets norm_1 + v_{1, j_1}$
    \STATE $norm_2 \gets norm_2 + v_{2, j_2}$
    \STATE $j_1 \gets j_1 + 1$
    \STATE $j_2 \gets j_2 + 1$
  \ENDIF
\ENDWHILE

\WHILE{$j_1 \leq length_1$}
  \STATE $norm_1 \gets norm_1 + v_{1, j_1}$
  \STATE $j_1 \gets j_1 + 1$
\ENDWHILE

\WHILE{$j_2 \leq length_2$}
  \STATE $norm_2 \gets norm_2 + v_{2, j_2}$
  \STATE $j_2 \gets j_2 + 1$
\ENDWHILE

\STATE return $c, s \gets jacobi(norm1, norm2, dotprod)$

\end{algorithmic}

